home *** CD-ROM | disk | FTP | other *** search
/ Run Magazine ReRun 1985 Winter / rerun-1985-winter.d64 / wedge utilities (.txt) < prev    next >
Commodore BASIC  |  2022-09-20  |  2KB  |  65 lines

  1. 10 rem sample utility programs
  2. 20 rem err-read disk error channel
  3. 30 close100:open100,8,15
  4. 40 input#100,n,er$,t,s
  5. 50 printn;er$;t;s:close100:end
  6. 60 rem hex-convert a number from decimal to hexadecimal
  7. 70 print"convert to hex"
  8. 80 d=0:input"decimal";d:ifd=0thenend
  9. 90 h$="":d=d/4096:fori=1to4:t%=d:h$=h$+chr$(48+t%-(t%>9)*7)
  10. 100 d=16*(d-t%):next:print"hex "h$:goto80
  11. 110 rem dec-convert from hexadecimal to decimal
  12. 120 print"convert to decimal"
  13. 130 h$="":input"hex";h$:ifh$=""thenend
  14. 140 d=0:fori=1to4:t%=asc(h$):t%=t%-48+(t%>64)*7
  15. 150 h$=mid$(h$,2):d=16*d+t%:next:print"decimal"d:goto130
  16. 160 rem init-initialize disk drive
  17. 170 close100:open100,8,15,"i":input#100,n,er$,t,s
  18. 180 ifn<>0then50
  19. 190 print"drive initialized":end
  20. 200 rem scratch-delete a file from disk
  21. 210 f$="":input"file";f$:iff$=""thenend
  22. 220 print"scratch "f$:input"sure (y/n)";r$:ifr$<>"y"thenend
  23. 230 close100:open100,8,15,"s0:"+f$:goto40
  24. 240 rem rename-rename a file
  25. 250 f1$="":input"old name";f1$:iff1$=""thenend
  26. 260 f2$="":input"new name";f2$:iff2$=""thenend
  27. 270 close100:open100,8,15,"r0:"+f2$+"="+f1$:goto40
  28. 280 rem header-format a new disk
  29. 290 f1$="":input"disk name";f1$:iff1$=""orlen(f1$)>16then290
  30. 300 f2$="":input"2 char id";f2$:iflen(f2$)<>2then300
  31. 310 print"this will erase disk":input"go ahead (y/n)";r$:ifr$<>"y"thenend
  32. 320 close100:open100,8,15,"n0:"+f1$+","+f2$:close100:goto20
  33. 330 rem dir-print disk directory
  34. 340 z$=chr$(0):close100:close101:open100,8,15:open101,8,0,"$0"
  35. 350 input#100,n,er$,t,s:ifn<>0then50
  36. 360 get#101,a$:ifa$<>""then360
  37. 370 printa$;:goto460
  38. 380 getc$:ifc$=""then420
  39. 390 ifc$<>" "then510
  40. 400 getc$:ifc$=""then400
  41. 410 ifc$<>" "then510
  42. 420 get#101,a$:s=st:a=asc(a$+z$)
  43. 430 get#101,b$:s=st:b=asc(b$+z$)
  44. 440 ifsthen510
  45. 450 ifa=1andb=1thengosub480
  46. 460 get#101,a$:ifa$=""thenprint:goto380
  47. 470 printa$;:goto460
  48. 480 get#101,a$:s=st:a=asc(a$+z$)
  49. 490 get#101,b$:s=st:b=asc(b$+z$)
  50. 500 n=b*256+a:printn;:return
  51. 510 close101:close100
  52. 520 end
  53. 530 rem help-print documentation
  54. 540 print:print"commands available are:"
  55. 550 print"err     -read error channel"
  56. 560 print"hex     -convert number to hex"
  57. 570 print"dec     -convert number to decimal"
  58. 580 print"init    -initialize disk drive"
  59. 590 print"scratch -delete disk file"
  60. 600 print"rename  -rename a disk file"
  61. 610 print"header  -format a new disk"
  62. 620 print"dir     -print the disk directory"
  63. 630 print"help    -print this help message"
  64. 640 end
  65.